Skip to content

test: add exhaustive AAAT unit tests for GeneralUpdate.Core (Round 4) - #434

Merged
JusterZhu merged 3 commits into
masterfrom
feature/core-unit-tests-round4
May 26, 2026
Merged

test: add exhaustive AAAT unit tests for GeneralUpdate.Core (Round 4)#434
JusterZhu merged 3 commits into
masterfrom
feature/core-unit-tests-round4

Conversation

@JusterZhu

Copy link
Copy Markdown
Collaborator

Summary

Adds 20 new test files covering all previously untested components in GeneralUpdate.Core, following the AAA (Arrange-Act-Assert) pattern with exhaustive branch coverage.

New test files

# File Component
1 Configuration/BlackListConfigBuilderTests.cs Fluent builder API, HasRules logic, ReadOnly wrappers
2 Configuration/ComparisonResultTests.cs AddToLeft/Right/Different, accumulation, ReadOnly
3 Configuration/UpdateOptionValueTests.cs Value types, nulls, boxing, ToString
4 Configuration/UpdateOptionsStaticTests.cs All static option defaults + singleton identity
5 Configuration/HubConfigTests.cs Property defaults, set/get, boundary values
6 Configuration/PacketTests.cs All nullable properties, tri-state bool?/int?
7 Configuration/VersionOSSTests.cs OSS version model, DateTime extremes
8 Configuration/VersionRespDTOTests.cs BaseResponseDTO, Code boundary, Body variants
9 Configuration/BaseConfigInfoTests.cs All 13 default property values
10 Configuration/ConfigurationMapperExtendedTests.cs MapToProcessInfo edge cases, CopyBaseFields cross-type
11 Download/DefaultDownloadPipelineTests.cs SHA256 match/mismatch/case-insensitive, null hash, file missing
12 Download/DownloadProgressReporterTests.cs Progress/completed/error callbacks, event dispatch
13 Download/DownloadModelsTests.cs DownloadAsset/Plan/Progress/Result value equality
14 Download/PacketDTOTests.cs PacketDTO, VersionRequest, VersionResponse
15 Pipeline/PatchMiddlewareTests.cs Null differ skip, success invoke, exception propagation
16 FileSystem/FileTreeDifferExtendedTests.cs ProduceDeltaPaths, ProduceDeletes, ShouldUseDeltaPatching
17 FileSystem/FileTreeSnapshotExtendedTests.cs FromEnumerator, empty/subdirectory enumeration, FileEntry
18 FileSystem/BlackListDefaultsTests.cs Default list contents, singleton identity
19 Tracer/GeneralTracerTests.cs All 5 log levels, Exception overloads, toggle, Dispose
20 Tracer/TextTraceListenerTests.cs Write/WriteLine, concurrent, dispose lifecycle

Branch coverage highlights

  • Path coverage: null input, empty input, single/multi-item, all enum members
  • Conditional coverage: HasRules all 8 combinations (hasFiles x hasFormats x hasDirs)
  • Boundary coverage: ShouldUseDeltaPatching at exact threshold, above, below, zero files, negative
  • Exception coverage: null differ skip, differ exception propagation, hash mismatch, file not found
  • Concurrency: EventManager thread safety, TextTraceListener concurrent writes

Test results

Total: 958 | Passed: 958 | Failed: 0 | Skipped: 0

Test plan

  • All 958 tests pass locally on net10.0
  • No warnings/errors from dotnet build
  • CI pipeline passes

🤖 Generated with Claude Code

Add 20 new test files covering previously untested components:
- Configuration: BlackListConfigBuilder, ComparisonResult, UpdateOptionValue,
  UpdateOptions defaults, HubConfig, Packet, VersionOSS, VersionRespDTO,
  BaseConfigInfo, ConfigurationMapper edge cases
- Download: DefaultDownloadPipeline (SHA256 verify), DownloadProgressReporter,
  DownloadAsset/Plan/Progress/Result models, PacketDTO/VersioRequest/VersionResponse
- FileSystem: FileTreeDiffer (ProduceDeltaPaths, ProduceDeletes,
  ShouldUseDeltaPatching), FileTreeSnapshot edge cases, BlackListDefaults
- Pipeline: PatchMiddleware (null differ skip, success, exception propagation)
- Tracer: GeneralTracer (all log levels, toggle, dispose), TextTraceListener

All 958 tests pass with 0 failures.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 26, 2026 03:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new xUnit test coverage for previously untested areas of GeneralUpdate.Core, with a focus on AAA-style unit tests and branch/edge-case coverage for configuration models, download pipeline/reporting, file-system diff/snapshotting, pipeline middleware, and tracing utilities.

Changes:

  • Added new unit tests for configuration DTOs/options/mappers and blacklist builder/defaults.
  • Added new unit tests for download DTOs/models, progress reporting event dispatch, and SHA256 verification pipeline behavior.
  • Added new unit tests for file snapshot/diff logic, patch middleware behavior, and tracer/listener lifecycle/concurrency.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/CoreTest/Tracer/TextTraceListenerTests.cs Exercises TextTraceListener write/write-line behavior, disposal, and concurrent writes.
tests/CoreTest/Tracer/GeneralTracerTests.cs Exercises GeneralTracer log methods, enable/disable toggle, and dispose behavior.
tests/CoreTest/Pipeline/PatchMiddlewareTests.cs Covers PatchMiddleware skip/invoke paths and exception propagation.
tests/CoreTest/FileSystem/FileTreeSnapshotExtendedTests.cs Adds edge-case coverage for FileTreeSnapshot ctor/factories and enumeration.
tests/CoreTest/FileSystem/FileTreeDifferExtendedTests.cs Adds coverage for delta path/delete production and delta-patching decision logic.
tests/CoreTest/FileSystem/BlackListDefaultsTests.cs Verifies BlackListDefaults static default contents and identity.
tests/CoreTest/Download/PacketDTOTests.cs Covers download DTO defaults, assignment, and nullable/tri-state fields.
tests/CoreTest/Download/DownloadProgressReporterTests.cs Covers callbacks + EventManager dispatch for progress/completed/failed/all-complete.
tests/CoreTest/Download/DownloadModelsTests.cs Covers value semantics/defaults for download model record types/enums.
tests/CoreTest/Download/DefaultDownloadPipelineTests.cs Covers DefaultDownloadPipeline hash verification and error/cancellation cases.
tests/CoreTest/Configuration/VersionRespDTOTests.cs Covers VersionRespDTO / BaseResponseDTO<T> defaults and assignment.
tests/CoreTest/Configuration/VersionOSSTests.cs Covers VersionOSS property defaults and assignments, including DateTime extremes.
tests/CoreTest/Configuration/UpdateOptionValueTests.cs Covers UpdateOptionValue<T> construction, boxing, ToString, and edge cases.
tests/CoreTest/Configuration/UpdateOptionsStaticTests.cs Verifies UpdateOptions static defaults and repeated-access identity.
tests/CoreTest/Configuration/PacketTests.cs Covers Packet default/nullables and tri-state bool/int properties.
tests/CoreTest/Configuration/HubConfigTests.cs Covers HubConfig defaults and boundary assignments.
tests/CoreTest/Configuration/ConfigurationMapperExtendedTests.cs Adds mapper edge-case coverage for ConfigurationMapper methods.
tests/CoreTest/Configuration/ComparisonResultTests.cs Covers ComparisonResult list accumulation and read-only list exposure.
tests/CoreTest/Configuration/BlackListConfigBuilderTests.cs Covers blacklist builder fluent API, null-vs-empty behavior, and HasRules.
tests/CoreTest/Configuration/BaseConfigInfoTests.cs Verifies BaseConfigInfo default values and set/get behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +17
private readonly ITestOutputHelper _output;

public DownloadProgressReporterTests(ITestOutputHelper output) => _output = output;
Comment on lines +19 to +22
public void Dispose()
{
EventManager.Instance.Clear();
}
Comment on lines +14 to +23
public GeneralTracerTests()
{
_originalTracingEnabled = GeneralTracer.IsTracingEnabled();
}

public void Dispose()
{
GeneralTracer.SetTracingEnabled(_originalTracingEnabled);
GC.SuppressFinalize(this);
}
Comment on lines +185 to +192
public void ProduceDeletes_IsSameReference_NotCopy()
{
var deleted = new[] { "x.txt" };
var diff = Diff(deleted: deleted);

var result = FileTreeDiffer.ProduceDeletes(diff);

Assert.Same(diff.Deleted, result);
Comment on lines +293 to +301
[Fact]
public void ShouldUseDeltaPatching_NegativeTotalFiles_ReturnsTrueBecauseRatioBelowThreshold()
{
// With totalFileCount = -1, the ratio is negative, which is <= 0.5, so returns true.
// This is a known edge case — ShouldUseDeltaPatching assumes positive totalFileCount.
var diff = Diff(added: new[] { Entry("a.txt") });
Assert.True(FileTreeDiffer.ShouldUseDeltaPatching(diff, -1));
}

Comment on lines +170 to +183
public void Builder_Reused_ReadOnlyWrapsUnderlyingList()
{
// Builder caches a single _blackFiles list. Build() wraps it with AsReadOnly(),
// which returns a live view of the underlying list. Subsequent AddBlackFiles
// calls mutate that same list, so earlier builds also see the accumulated items.
var builder = new BlackListConfigBuilder();
builder.AddBlackFiles("a.dll");
var first = builder.Build();
builder.AddBlackFiles("b.dll");
var second = builder.Build();

// Both see the accumulated list because ReadOnlyCollection wraps the same List<string>
Assert.Equal(2, first.BlackFiles!.Count);
Assert.Equal(2, second.BlackFiles!.Count);

var config = builder.Build();

Assert.NotNull(config.BlackFiles);
Comment on lines +212 to +227
[Theory]
[InlineData(true, false, false)]
[InlineData(false, true, false)]
[InlineData(false, false, true)]
[InlineData(true, true, true)]
public void HasRules_WhenAnySectionHasItems_ReturnsTrue(bool hasFiles, bool hasFormats, bool hasDirs)
{
var builder = new BlackListConfigBuilder();
if (hasFiles) builder.AddBlackFiles("f.dll");
if (hasFormats) builder.AddBlackFormats(".log");
if (hasDirs) builder.AddSkipDirectories("tmp");

var config = builder.Build();

Assert.True(config.HasRules);
}
JusterZhu and others added 2 commits May 26, 2026 11:57
Renamed "INT_KEY" to "INT_KEY_UV" in UpdateOptionValueTests to prevent
registry collision with ConfigurationModelsTests. UpdateOption.ValueOf
uses a static ConcurrentDictionary — same key with different defaults
causes test ordering-dependent failures on Windows CI.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Remove unused ITestOutputHelper field in DownloadProgressReporterTests
- Add NonParallel_EventManager collection for EventManager/GeneralTracer tests
  to prevent parallel test race conditions with global singleton state
- Change ProduceDeletes assertion from brittle Assert.Same to content check
- Remove invalid negative totalFileCount test case from FileTreeDiffer tests
- Remove leaky builder-reuse test that enshrined mutable internal state
- Rename Build_ReadOnlyLists to Build_ProducesNonNullLists to match assertions
- Complete HasRules theory to cover all 8 input combinations (2^3)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@JusterZhu
JusterZhu merged commit 5a23b31 into master May 26, 2026
3 checks passed
@JusterZhu
JusterZhu deleted the feature/core-unit-tests-round4 branch May 26, 2026 04:06
@JusterZhu JusterZhu linked an issue May 26, 2026 that may be closed by this pull request
27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exhaustive AAAT unit tests for GeneralUpdate.Core — untested component coverage

2 participants